package com.yanqu.road.server.cmd.badge;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.badge.BadgeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHANGE_BADGE_SHOW, desc = "更改徽章展示")
public class ChangeBadgeShowCmd extends AbstractCommand {

    private String badge;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BadgeProto.ChangeBadgeShowReqMsg reqMsg = BadgeProto.ChangeBadgeShowReqMsg.parseFrom(packet.getBytes());
        badge = reqMsg.getBadge();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(PlayerModule.class).changeBadge(badge);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            BadgeProto.ChangeBadgeShowRespMsg.Builder respMsg = BadgeProto.ChangeBadgeShowRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_BADGE_SHOW_CHANGE, respMsg);
        }
    }
}
